home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-08 | 49.2 KB | 1,538 lines |
- ;$Id: d_wavelet.pro,v 1.23 1997/04/25 22:19:33 tremblay Exp $
- ;
- ; Copyright (c) 1997, Research Systems, Inc. All rights reserved.
- ; Unauthorized reproduction prohibited.
- ;
- ;+
- ; FILE:
- ; d_wavelet.pro
- ;
- ; CALLING SEQUENCE: d_wavelet
- ;
- ; PURPOSE:
- ; This example demonstrates the wavelets orthogonal functions
- ;
- ; MAJOR TOPICS: Plotting and data analysis
- ;
- ; CATEGORY:
- ; IDL 5.0
- ;
- ; INTERNAL FUNCTIONS and PROCEDURES:
- ; fun wv_cutoff - Returns a threshold value
- ; fun decimate - Set values within threshold limits
- ; pro get_wavelet_basis - Compute the wavelet basis
- ; fun adjust_size - Adjust data size
- ; fun in_range - Set values within a give n range
- ; pro no_compressed_image - Handle the no compressed image state
- ; pro reset_plot - Reset the plots
- ; pro Update_plot - Redraw the plots
- ; pro new_percentage - Set to a new percentage (slider)
- ; pro move_line - Move the plot line
- ; pro moveSlider - Update slider value
- ; pro got_new_image - Display the image
- ; pro sensitize - Sensitize a widget
- ; pro ChangeFilename - Update the title
- ; pro erase_original - Erase the original image
- ; pro erase_secondary - Erase the secondary image
- ; pro data_input - Load a new data set
- ; pro do_compression - Compute and display the compressed image
- ; pro new_coeff - Handle the new coefficients
- ; pro waveletTool_Event - Event handler
- ; pro wavelet_Cleanup - Cleanup
- ; pro d_wavelet - Main procedure
- ;
- ; EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
- ; pro getdata2 - Read new data
- ; wavelet.txt
- ; wavelet.tip
- ; abnorm1.dat
- ; convec.dat
- ; ctscan.dat
- ; head.dat
- ; hurric.dat
- ; m51.dat
- ; nyny.dat
- ; sunflare.dat
- ; venus_1.dat
- ; venus_2.dat
- ; venus_e.dat
- ; worldelv.dat
- ;
- ; REFERENCE: IDL Reference Guide, IDL User's Guide
- ;
- ; NAMED STRUCTURES:
- ; none.
- ;
- ; COMMON BLOCS:
- ; none.
- ;
- ; MODIFICATION HISTORY:
- ; 95, DS - Written.
- ; 11/95, DAT - Modified for IDL 5.0 demo
- ;-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE
- ; Return array of threshold value versus (% decimation * 10.)
- ; For example, to get cutoff value for decimation of 60%,
- ; use cutoff(60 * 10).
- ; Inputs:
- ; Wavelet = array containing wavelet transform.
- ; Outputs:
- ; Wvlog = log10 of wavelet transform (elements less than 10^(-4)
- ; are set to 10^(-4).
- ; Cutoff = 1001 element array containing threshold value versus
- ; % decimation.
- ;
- ;
-
- ;+
- ; NAME:
- ; GetData2
- ; PURPOSE:
- ; Retrieves a data file from the images directory in the main IDL
- ; directory. The file can be specified when calling the routine
- ; or the file can be chosen by the user with a widget that lets them
- ; make the selection.
- ; CATEGORY:
- ; Widgets
- ; CALLING SEQUENCE:
- ; GetData2, NEWDATA
- ; KEYWORD PARAMETERS:
- ; ASSOC_IT = When set, this keyword forces the routine to return
- ; an associated variable instead of a standard IDL variable.
- ; This is more efficient when loading animations for instance
- ; as it removes the need to create two copies of the data
- ; in memory (one for the animation, one for the load data).
- ; DESCRIPTION = This keyword returns the description of the data
- ; selected by the GetData routine (NEWDATA).
- ; DIMENSIONS = This keyword returns the dimensions of the data
- ; selected by the GetData routine. These dimensions
- ; are the dimensions of the NEWDATA variable.
- ; FILENAME = The name of the file that is to be selected from the
- ; images subdirectory. If this keyword is set, no user
- ; selection widget is created.
- ; OFILENAME = name of file selected.
- ; ONE_DIM = This keyword is set when the routine is to consider
- ; one dimensional data from the data contained in the
- ; images subdirectory.
- ; TWO_DIM = This keyword is set when the routine is to consider
- ; two dimensional data from the data contained in the
- ; images subdirectory. When searching for two dimensional
- ; data, this routine will use the first slice of any
- ; three dimensional data that it encounters.
- ; THREE_DIM = This keyword is set when the routine is to consider
- ; three dimensional data from the data contained in the
- ; images subdirectory.
- ; TITLE = The string that will appear in the title portion
- ; of the data selection widget. If not specified, the
- ; title will be "Please Select Data".
- ; OUTPUTS:
- ; NEWDATA = the variable that is to be filled with the new data.
- ; COMMON BLOCKS:
- ; GF - maintains which selection was made when using the data
- ; selection widget.
- ; SIDE EFFECTS:
- ; Desensitizes all the other widgets and is modal in behavior. It
- ; forces the user to make a selection before proceeding with other
- ; widget functions.
- ; RESTRICTIONS:
- ; Getdat2 must find the subdirectory called examples/dataimages of
- ; the main IDL directory(IDL_DIR) and the directory must contain a
- ; file called data.txt that describes the contents of the directory.
- ; PROCEDURE:
- ; If the FILENAME keyword was not set, determine the file name using
- ; a widget that lets the user make a selection from the data.txt file
- ; and then open that file, read the data, dimensions, and description,
- ; and return the data.
- ; MODIFICATION HISTORY:
- ; Written by Steve Richards, Dec, 1990
- ; Modified by DAT, renamed getData2, add group keyword, 2/97
- ;-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Event handler
- ;
- pro GetData2_event, $
- event ; IN: event structure.
-
- COMMON GF, selection
-
- WIDGET_CONTROL, event.id, GET_UVALUE=selected
-
- case selected of
- "FILELST": begin
- WIDGET_CONTROL, event.top, SENSITIVE=0
- WIDGET_CONTROL, event.top, /DESTROY
- selection = event.index + 1
- end ; of FILELST
-
- "CANCEL": WIDGET_CONTROL, event.top, /DESTROY
- endcase
-
- end ; of GetData_event
-
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Main procedure.
- ; Retrieves a data file from the images directory in the main IDL
- ; directory. The file can be specified when calling the routine
- ; or the file can be chosen by the user with a widget that lets them
- ; make the selection.
- ;
- pro GetData2, $
- NEWDATA, $ ; OUT: new data set
- GROUP=group, $ ; IN: (opt) group leader identifer.
- DESCRIPTION = DESCRIPTION, $ ; OUT: (opt)Data set description.
- DIMENSIONS = DIMENSIONS, $ ; OUT: (opt) dimension of the data set
- ONE_DIM = ONE_DIM, $ ; IN: (opt) Routine will consider 1-D data.
- TWO_DIM = TWO_DIM, $ ; IN: (opt) Routine will consider 2-D data.
- THREE_DIM = THREE_DIM, $ ; IN: (opt) Routine will consider 3-D data.
- TITLE = TITLE, $ ; IN: (opt) Selection window title.
- FILENAME = FILENAME, $ ; IN: File name of the data set.
- OFILENAME = OFILENAME, $ ; OUT: (opt) output file name.
- ASSOC_IT = ASSOC_IT ; IN: (opt) routine returns an associate
- ; variable instead of IDL variable.
-
- COMMON GF, selection
-
- ; For demo 5, the image files are located in the same directory
- ; tnan this procedure. Therefore, the data path is set to ' ' .
- ;
- datapath = filepath('', SUBDIR=['examples','data'])
-
- ; Initialize working variables.
- ;
- name = ''
- dim = LONARR(3)
- des = ''
- del = ''
- numfiles = 0L
- ONE_MASK = 1
- TWO_MASK = 2
- THREE_MASK = 4
-
- NEWDATA = 0
- DESCRIPTION = 0
- DIMENSIONS = 0
-
- if (KEYWORD_SET(FILENAME)) then begin
- OPENR, unit, datapath + "data.txt", /GET_LUN
- READF, unit, numfiles
- if (numfiles NE 0) then begin
- goodindex = 0
- nameindex = 0
-
- while((nameindex LT (numfiles)) AND (goodindex EQ 0)) do begin
- READF, unit, name, dim, des, del
- if (name EQ FILENAME) then goodindex = 1
- if (del NE '*') then MESSAGE, $
- "* delimiter not found in data.txt"
- endwhile
-
- FREE_LUN, unit
-
- if (goodindex NE 0) then begin
- ofilename = filename
- OPENR, unit, datapath + FILENAME, /GET_LUN, /BLOCK
-
- if (KEYWORD_SET(ASSOC_IT)) then begin
- NEWDATA = ASSOC(unit, BYTARR(dim(0),dim(1)))
- endif else begin
- NEWDATA = bytarr(dim(0), dim(1), dim(2))
- READU, unit, NEWDATA
- FREE_LUN, unit
- endelse
-
- DESCRIPTION = des
- DIMENSIONS = dim
- endif
- endif
- endif else if ((XRegistered("GetData2") EQ 0)) then begin
-
- FILTER = 0
-
- if (KEYWORD_SET(ONE_DIM)) then begin
- FILTER = FILTER OR ONE_MASK
- endif
-
- if (KEYWORD_SET(TWO_DIM)) then begin
- FILTER = FILTER OR TWO_MASK OR THREE_MASK
- endif
-
- if (KEYWORD_SET(THREE_DIM)) then begin
- FILTER = FILTER OR THREE_MASK
- endif
-
- if ((FILTER EQ 0)) then begin
- FILTER = ONE_MASK + TWO_MASK + THREE_MASK
- endif
-
- OPENR, unit, datapath + "data.txt", /GET_LUN
- READF, unit, numfiles
- if (numfiles NE 0) then begin
- names = STRARR(numfiles)
- descriptions = STRARR(numfiles)
- dimensions = LONARR(3,numfiles)
- goodindex = 0
-
- for nameindex = 0, numfiles - 1 do begin
- READF, unit, name, dim, des, del
- TEMPFILT = 0
- if (DIM(0) GT 1) then TEMPFILT = ONE_MASK
- if (DIM(1) GT 1) then TEMPFILT = TWO_MASK
- if (DIM(2) GT 1) then TEMPFILT = THREE_MASK
-
- if ((TEMPFILT AND FILTER) NE 0) then begin
- names(goodindex) = name
- dimensions(*,goodindex) = dim
- descriptions(goodindex) = des
- goodindex = goodindex + 1
- endif
-
- if (del NE '*') then begin
- MESSAGE, "* delimiter not found in data.txt"
- endif
-
- endfor
-
- FREE_LUN, unit
-
- neworder = SORT(names(0:goodindex-1))
- names = names(neworder)
- descriptions = descriptions(neworder)
- dimensions = dimensions(*,neworder)
-
- filler = "........................................"
- fullnames = STRARR(goodindex)
-
- for i = 0, goodindex - 1 do begin
- dimstring = STRING(dimensions(*,i), $
- FORMAT = '("[",I0.3,", ",I0.3,", ",I0.3,"]")')
- length = STRLEN(names(i))
- lengthdim = STRLEN(dimstring)
- fullnames(i) = descriptions(i)
- ; fullnames(i) = names(i) + $
- ; STRMID(filler, 0, 30-length) + $
- ; dimstring + $
- ; STRMID(filler, 0, 30-lengthdim) + $
- ; descriptions(i)
- endfor
-
- if (NOT(KEYWORD_SET(TITLE))) then TITLE = "Please Select Data"
-
- ; font = '*fixed*' ;It seems to be impossible to find
- ; a simple font on all servers.
-
- if (NOT(KEYWORD_SET(group))) then begin
-
- loadbase = WIDGET_BASE(TITLE = TITLE, $
- /COLUMN, $
- XPAD = 50, $
- YPAD = 50, $
- SPACE = 20)
- endif else begin
- loadbase = WIDGET_BASE(TITLE = TITLE, $
- GROUP_LEADER=group, /MODAL, $
- /COLUMN, $
- XPAD = 50, $
- YPAD = 50, $
- SPACE = 20)
- endelse
-
- loadbox = WIDGET_BASE(loadbase, $
- /COLUMN, $
- /FRAME, $
- SPACE=10)
-
- loadlist = WIDGET_LIST(loadbox, $
- VALUE=fullnames, $
- UVALUE="FILELST", $
- YSIZE=10)
-
- loadcancel = WIDGET_BUTTON(loadbase, $
- VALUE="Cancel", UVALUE="CANCEL")
-
- WIDGET_CONTROL, loadbase, /REALIZE
-
- selection = 0
-
- XMANAGER, "GetData2", loadbase
-
- if (selection NE 0) then begin
-
- if ((NOT(KEYWORD_SET(THREE_DIM))) AND $
- (dimensions(2,selection-1) NE 1)) then $
- dimensions(2,selection-1) = 1
-
- OPENR, unit, datapath + $
- names(selection - 1), /GET_LUN, /BLOCK
- ofilename = names(selection - 1)
-
- if (KEYWORD_SET(ASSOC_IT)) then begin
- NEWDATA = ASSOC(unit, $
- BYTARR(dimensions(0, selection-1), $
- dimensions(1, selection-1)))
- endif else begin
- NEWDATA = BYTARR(dimensions(0, selection - 1), $
- dimensions(1, selection - 1), $
- dimensions(2, selection - 1))
- READU, unit, NEWDATA
- FREE_LUN, unit
- endelse
-
- DESCRIPTION = descriptions(selection - 1)
- DIMENSIONS = dimensions(*,selection - 1)
-
- endif ; of keyword set three_dim
- endif ; of selection NE 0
- endif ; of keyword set filename.
-
- end ; of GETDATA2
-
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Compute the cutoff paramater.
- ;
- function WV_CUTOFF, $
- wavelet ; IN: wavelet coefficients.
-
- lowthr = 4 ; Consider only values over 10-lowthr
- nhist = 1000 ; Number of histogram bins
- nbins = 1000 ; Number of returned bins
-
- wvlog = alog10(abs(wavelet) > (10.0^(-lowthr))) + lowthr
- wlmin = min(wvlog, MAX = wlmax)
- bins = (wlmax - wlmin) / nhist
- h = histogram(wvlog, min = wlmin, max = wlmax, binsize = bins) / $
- float(n_elements(wvlog))
- for i=1, nhist-1 do h(i) = h(i) + h(i-1) ;Cumulative integral
-
- ; This plus 1 for maximum value.
- ;
- cutoff = FLTARR(nbins+1)
- j = 0
- for i=1, nbins-1 do begin
- t = float(i) / nbins
- while (h(j) lt t) and (j lt nhist) do j = j + 1
- cutoff(i) = j
- endfor
- cutoff = 10.0 ^ (cutoff * (wlmax/nhist) - lowthr)
-
- ; Cutoff 1000 must hold the max value of the array
- ;
- cutoff(1000) = max(abs(wavelet))
-
- RETURN, cutoff
-
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Set the data to zero when below threshold value.
- ;
- function DECIMATE, original, threshold
- new = original
- d = where(abs(new) le threshold, count)
-
- ; If d=-1 then there is noplace like that
- ;
- if (count GT 0) then new(d) = 0.0
- return, new
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Clamp and scale input data and then display.
- ; Assumes display is set to desired window
- ;
- pro demo_wvlt_tv, input
- input = input > 0
- input = input < 255
- TVSCL, input
- end
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Compute the wavelet basis.
- ;
- pro Get_Wavelet_Basis, $
- UVAL ; IN: uval structure
-
- ; Given our uncompressed array
- ; and coefficients, get a new
- ; wavelet basis for the image
- ;
- WIDGET_CONTROL, /HOURGLASS
- UVAL.WVLT_IMG = NR_WTN(UVAL.ORIG_IMG, UVAL.COEFFS)
-
- UVAL.THRESHARRAY = WV_CUTOFF(UVAL.WVLT_IMG)
-
- ; Now we need to tv the image of the
- ; undecimated and decimated wavelet bases
- ;
- WSET, UVAL.ID_WAVE1
- demo_wvlt_tv, CONGRID (UVAL.WVLT_IMG, 200, 200)
-
- ; Now we need to create the new plot
- ;
- Percent_Plot, UVAL
- Reset_Plot, UVAL
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Adjust the viewwing area size.
- ;
- function Adjust_Size, $
- Orig_Image ; IN: original image
-
- s = SIZE(Orig_Image)
-
- if ((s(1) EQ 256) AND (s(2) EQ 256)) then begin
- New_Image = Orig_Image
- endif else begin
- New_Image = CONGRID (Orig_Image, 256, 256, /INTERP)
- endelse
-
- RETURN, New_Image
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Make the data to fall within a range
- ;
- function IN_RANGE, $
- VALUE, $ ; IN: data
- MINVAL, $ ; IN: minimum value
- MAXVAL ; IN: maximum value
-
- tmp = VALUE
-
- if (tmp LT MINVAL) then $
- tmp = MINVAL $
- ELSE if (tmp GT MAXVAL) then tmp = MAXVAL
-
- return, tmp
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : This procedure clears the compressed image
- ; and erase an image if appropriate.
- ;
- pro No_Compressed_Image, UVAL
-
- ; This procedure clears the compressed image
- ; and erase an image if appropriate.
- ;
- if (UVAL.COMPRESSED EQ 1B) then begin
- WSET, UVAL.ID_COMP
- erase
- ; do X plot
- plots, [0,255],[0,255],/DEVICE
- plots, [0,255],[255,0],/DEVICE
- UVAL.COMP_IMG=0
- empty
- if NOT(Widget_Info(UVAL.WID_DIFFBASE, /Valid_Id)) then begin
- B_DIFF = WIDGET_BASE(GROUP_LEADER=UVAL.WID_MAIN, $
- COLUMN=1, MAP=0, $
- TITLE='WaveletTool Image Differences')
-
- D_DIFF = WIDGET_DRAW( B_DIFF, $
- RETAIN=2, XSIZE=256, YSIZE=256, /FRAME)
-
- WIDGET_CONTROL, B_DIFF, /Realize
- WIDGET_CONTROL, D_DIFF, get_value=NEW_DIFF_ID
- UVAL.ID_DIFF = NEW_DIFF_ID
- UVAL.WID_DIFFBASE = B_DIFF
- endif
- WSET, UVAL.ID_DIFF
- erase
-
- ; do X plot
- plots, [0,255],[0,255],/DEVICE
- plots, [0,255],[255,0],/DEVICE
- empty
- UVAL.COMPRESSED = 0B
- endif
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Reset (empty) the drawing plots.
- ;
- pro Reset_Plot, $
- UVAL ; IN: uval structure
-
- ; Reset plots.
- ;
- New_Percentage, UVAL, 0.0
- Move_Line, UVAL, 0.0
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Refresh is set to 0/1 depending on whether we simply
- ; want to refresh the data in the plot.
- ;
- pro Percent_Plot, $
- UVAL ; IN: uval structure
-
- WSET, UVAL.ID_PLOT
- plot_io, FINDGEN(1000)/10, UVAL.THRESHARRAY, $
- ytitle='Threshold', $
- Xtitle='% compression', YCHARSIZE=UVAL.CHARSIZE, $
- XCHARSIZE=UVAL.CHARSIZE
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Update the compression plot.
- ;
- pro Update_Plot, $
- UVAL ; IN: uval structure
-
- ; Refresh is set to 0/1 depending on whether we simply
- ; want to refresh the data in the plot
- ;
- WSET, UVAL.ID_PLOT
- PLOT_IO, FINDGEN(1000)/10, UVAL.THRESHARRAY, YTITLE='Threshold', $
- XTITLE='% compression', $
- /NOERASE, YCHARSIZE=UVAL.CHARSIZE, $
- XCHARSIZE=UVAL.CHARSIZE
-
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Adjust the plot and slider to the new percentage value.
- ;
- pro New_Percentage, $
- UVAL , $ ; IN: uval structure
- PERCENT ; IN: precentage value
-
- WIDGET_CONTROL,/hourglass
-
- ; Send a 1 to move_line to refresh plot b/t draws.
- ;
- UVAL.PERCENTAGE = PERCENT
-
- ; Get the appropriate threshold and save it
- ; (from the plotted dataset!).
- ;
- UVAL.THRESHOLD = UVAL.THRESHARRAY (UVAL.PERCENTAGE * 10)
- Move_Slider, UVAL
- textChange = ['void','comp1', 'comp2']
- putTips, UVAL.sText, UVAL.wText[1], $
- textChange, [0,1,2]
- Update_Plot, UVAL
-
- ; Then it decimates and displays the new image
- ; into the decimated wavelet draw widget.
- ;
- WSET, UVAL.ID_WAVE2
- demo_wvlt_tv, CONGRID (Decimate(UVAL.WVLT_IMG, UVAL.THRESHOLD), 200, 200)
- textChange = ['selecto','adjus', 'perce']
- putTips, UVAL.sText, UVAL.wText[1], $
- textChange, [0,1,2]
-
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Redraw the vertical line of the compression plot.
- ;
- pro Move_Line, $
- UVAL , $ ; IN: uval structure
- X ; IN: precentage value
-
- ; Expects X in DATA coordinates.
- ;
- WSET, UVAL.ID_PLOT
- device, SET_GRAPHICS_FUNCTION=6
- plots, [UVAL.PERCENTAGE, UVAL.PERCENTAGE],[1e-10, 1e+10], $
- NOCLIP=0, /DATA, COLOR=200
- empty
- plots, [X,X],[1e-10, 1e+10], NOCLIP=0, /DATA, COLOR=200
- device, SET_GRAPHICS_FUNCTION=3
- xValue = STRING(UVAL.percentage, FORMAT='(f6.2)')
- xValue = STRTRIM(xValue,2)
- xValue = xValue + ' %'
- WIDGET_CONTROL, UVAL.SliderValue, SET_VALUE=xValue
- empty
-
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Update the slider to the new percentage value.
- ;
- pro Move_Slider, $
- UVAL ; IN: uval structure
-
- WIDGET_CONTROL, UVAL.WID_SLIDER, SET_VALUE=UVAL.PERCENTAGE
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Redo plots with new image.
- ;
- PRO Got_New_Image, $
- UVAL ; IN: uval structure
-
- ; Display it.
- ;
- textChange = ['void','comp1', 'comp2']
- putTips, UVAL.sText, UVAL.wText[1], $
- textChange, [0,1,2]
- WSET, UVAL.ID_ORIG
- TVSCL, UVAL.ORIG_IMG
-
- ; Get wavelet basis for this image .
- ;
- Get_Wavelet_Basis, UVAL
- textChange = ['selecto','adjus', 'perce']
- putTips, UVAL.sText, UVAL.wText[1], $
- textChange, [0,1,2]
- WIDGET_CONTROL, UVAL.SliderValue, SET_VALUE=' 75.00%'
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Redo plots with new image.
- ;
- pro Sensitize, $
- UVAL, $ ; IN: uval structure
- SENSE ; IN: sensitive case (0 or 1)
-
- ; Using ENABLE_WIDS, sensitize/desensitize
- ; the appropriate widgets.
- ;
- for i=0,(N_ELEMENTS(UVAL.ENABLE_WIDS)-1) do $
- WIDGET_CONTROL, UVAL.ENABLE_WIDS(i), SENSITIVE=SENSE
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Change the top level base name to new file name.
- ;
- pro Change_Filename, $
- UVAL, $ ; IN: uval structure
- Filename ; IN: file name (string)
-
- WIDGET_CONTROL, UVAL.WID_MAIN, $
- TLB_SET_TITLE='WaveletTool - '+Filename
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Erases original image draw widget.
- ;
- pro Erase_Original, $
- UVAL ; IN: uval structure
-
- WSET, UVAL.ID_ORIG
- erase
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Erases original image draw widget.
- ;
- pro Erase_Secondary, $
- UVAL ; IN: uval structure
-
- WSET, UVAL.ID_WAVE1
- erase
- WSET, UVAL.ID_WAVE2
- erase
- WSET, UVAL.ID_PLOT
- erase
- No_Compressed_Image, UVAL
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Get a new data set.
- ;
- pro Data_Input, $
- UVAL ; IN: uval structure
-
- GetData2, NewImage, OFILENAME= file, /TWO_DIM, $
- GROUP=UVAL.B_MAIN
-
- WIDGET_CONTROL,/hourglass
-
- ; If file is undefined, no selection
- ;
- if (N_ELEMENTS(file) NE 0) then begin
-
- ; Got one, allow input to other widgets
- ;
- Change_Filename, UVAL, file
-
- ; Adjust size of image to 256,256 if necessary
- ;
- UVAL.ORIG_IMG = Adjust_Size (NewImage)
- UVAL.FILE_LOADED = 1B
- Sensitize, UVAL, 1
- Erase_Original, UVAL
- Erase_Secondary, UVAL
- Got_New_Image, UVAL
- textChange = ['selecto','adjus', 'perce']
- putTips, UVAL.sText, UVAL.wText[1], $
- textChange, [0,1,2]
-
- endif
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Given the wavelet basis and the setting
- ; on the slider, do the compression and display it.
- ;
- pro Do_Compression, $
- UVAL ; IN: uval structure
-
- WIDGET_CONTROL, /HOURGLASS
- WSET, UVAL.ID_COMP
- erase
- tmp = NR_WTN(DECIMATE (UVAL.WVLT_IMG, UVAL.THRESHOLD), $
- UVAL.COEFFS, /INVERSE)
-
- ; Range the value of the compressed image between 0 and 255.
- ;
- tmp = tmp > 0
- tmp = tmp < 255
-
- UVAL.COMP_IMG = tmp
- demo_wvlt_tv, tmp
-
- if (NOT(Widget_Info(UVAL.WID_DIFFBASE, /Valid_Id))) then begin
- B_DIFF = WIDGET_BASE(GROUP_LEADER=UVAL.WID_MAIN, $
- COLUMN=1, MAP=0, $
- TITLE='WaveletTool Image Differences')
-
- D_DIFF = WIDGET_DRAW( B_DIFF, RETAIN=2, $
- XSIZE=256, YSIZE=256, /FRAME)
-
- WIDGET_CONTROL, B_DIFF, /Realize
- WIDGET_CONTROL, D_DIFF, get_value=NEW_DIFF_ID
- UVAL.ID_DIFF = NEW_DIFF_ID
- UVAL.WID_DIFFBASE = B_DIFF
- endif
-
- WSET, UVAL.ID_DIFF
- erase
- UVAL.differenceImage = bytscl((UVAL.ORIG_IMG - tmp) > 0, $
- top=!d.table_size-1)
- UVAL.compressImageFlag = 1
- demo_wvlt_tv, UVAL.differenceImage
- UVAL.COMPRESSED = 1B
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Get a new wavelet basis, clear the draw window,
- ; recompute the new image (do compresssion) and
- ; display that image.
- ;
- pro New_Coeff, $
- UVAL, $ ; IN: uval structure
- COEFF ; IN: wavelet coeeficients
-
- if (COEFF NE UVAL.COEFFS) then begin
- UVAL.COEFFS = COEFF
-
- if (UVAL.FILE_LOADED EQ 1B) then begin
- textChange = ['void','comp1', 'comp2']
- putTips, UVAL.sText, UVAL.wText[1], $
- textChange, [0,1,2]
- Erase_Secondary, UVAL
- Get_Wavelet_Basis, UVAL
- textChange = ['selecto','adjus', 'perce']
- putTips, UVAL.sText, UVAL.wText[1], $
- textChange, [0,1,2]
- endif
- endif
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Save the compressed image.
- ;
- ;pro Do_Save, $
- ; UVAL ; IN: uval structure
- ;
- ; file = PICKFILE(/WRITE, FILTER='*.dat', GROUP=UVAL.WID_MAIN)
- ; if (file NE '') then begin
- ;
- ; ; Only write if a file was selected.
- ; ;
- ; openw, unit, /GET_LUN, file, /XDR
- ; writeu, unit, UVAL.COMP_IMG
- ; free_lun, unit
- ; endif
- ;end
- ;
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Main event handler.
- ;
- pro WaveletTool_Event, $
- Event ; IN: event structure
-
- if (TAG_NAMES(Event, /STRUCTURE_NAME) EQ $
- 'WIDGET_KILL_REQUEST') then begin
- WIDGET_CONTROL, Event.top, /DESTROY
- RETURN
- endif
-
- WIDGET_CONTROL,Event.Id,GET_UVALUE=WidUvalue
- WIDGET_CONTROL,Event.Top, GET_UVALUE=UVAL, /NO_COPY
-
- case WidUvalue of
-
- ; Open a new file (new data set).
- ;
- 'OPEN': begin
- Data_Input, UVAL
- WIDGET_CONTROL, UVAL.B_MAIN, SENSITIVE=0
- UVAL.compressImageFlag = 0
-
- perc = 75L
- Move_Line, UVAL, perc
- New_Percentage, UVAL, perc
- xValue = STRING(perc, FORMAT='(f6.2)')
- xValue = STRTRIM(xValue,2)
- xValue = xValue + ' %'
- WIDGET_CONTROL, UVAL.SliderValue, SET_VALUE=xValue
- Do_Compression, UVAL
- WIDGET_CONTROL, UVAL.B_MAIN, SENSITIVE=1
-
- WIDGET_CONTROL, UVAL.B_MAIN, SENSITIVE=1
-
- end
-
- ; Quit this application.
- ;
- 'QUIT': begin
- WIDGET_CONTROL,Event.Top, SET_UVALUE=UVAL, /NO_COPY
- WIDGET_CONTROL,Event.Top, /destroy
-
- ; Return after this!
- ;
- return
- end
-
- ; Compute the wavelet transform with 4 coefficients.
- ;
- 'FOUR': begin
- WIDGET_CONTROL, UVAL.B_MAIN, SENSITIVE=0
- WIDGET_CONTROL, UVAL.wFourButton, SENSITIVE=0
- WIDGET_CONTROL, UVAL.wTwelveButton, SENSITIVE=1
- WIDGET_CONTROL, UVAL.wTwentyButton, SENSITIVE=1
- New_Coeff, UVAL, 4
- Do_Compression, UVAL
- WIDGET_CONTROL, UVAL.SliderValue, SET_VALUE='000.00%'
- WIDGET_CONTROL, UVAL.B_MAIN, SENSITIVE=1
- end
-
- ; Compute the wavelet transform with 12 coefficients.
- ;
- 'TWELVE': begin
- WIDGET_CONTROL, UVAL.B_MAIN, SENSITIVE=0
- WIDGET_CONTROL, UVAL.wFourButton, SENSITIVE=1
- WIDGET_CONTROL, UVAL.wTwelveButton, SENSITIVE=0
- WIDGET_CONTROL, UVAL.wTwentyButton, SENSITIVE=1
- New_Coeff, UVAL, 12
- WIDGET_CONTROL, UVAL.SliderValue, SET_VALUE='000.00%'
- Do_Compression, UVAL
- WIDGET_CONTROL, UVAL.B_MAIN, SENSITIVE=1
- end
-
- ; Compute the wavelet transform with 20 coefficients.
- ;
- 'TWENTY': begin
- WIDGET_CONTROL, UVAL.B_MAIN, SENSITIVE=0
- WIDGET_CONTROL, UVAL.wFourButton, SENSITIVE=1
- WIDGET_CONTROL, UVAL.wTwelveButton, SENSITIVE=1
- WIDGET_CONTROL, UVAL.wTwentyButton, SENSITIVE=0
- New_Coeff, UVAL, 20
- Do_Compression, UVAL
- WIDGET_CONTROL, UVAL.SliderValue, SET_VALUE='000.00%'
- WIDGET_CONTROL, UVAL.B_MAIN, SENSITIVE=1
- end
-
- ; Show the difference between the original and the
- ; compressed image.
- ;
- 'DIFFERENCE': begin
- if (UVAL.compressImageFlag eq 1) then begin
- if not(Widget_Info(UVAL.WID_DIFFBASE, $
- /Valid_Id)) then begin
-
- B_DIFF = WIDGET_BASE(GROUP_LEADER= $
- UVAL.WID_MAIN, $
- COLUMN=1, MAP=0, $
- TITLE='WaveletTool Image Differences')
-
- D_DIFF = WIDGET_DRAW( B_DIFF, $
- RETAIN=2, XSIZE=256, YSIZE=256, /FRAME)
-
- WIDGET_CONTROL, B_DIFF, /REALIZE
- WIDGET_CONTROL, D_DIFF, get_value=NEW_DIFF_ID
- UVAL.ID_DIFF = NEW_DIFF_ID
- UVAL.WID_DIFFBASE = B_DIFF
- WSET, NEW_DIFF_ID
- demo_wvlt_tv, UVAL.differenceImage
- endif
-
- ; Map the showdiff base
- ;
- WIDGET_CONTROL, UVAL.WID_DIFFBASE, MAP=1
- WIDGET_CONTROL, UVAL.WID_DIFFBASE, /SHOW
- endif
- end
-
- ; Load a new color table.
- ;
- 'XLOADCT': begin
- WIDGET_CONTROL,Event.Top, SET_UVALUE=UVAL, /NO_COPY
- WIDGET_CONTROL,/hourglass
- XLoadct, GROUP=Event.top
- RETURN
- end
-
- ; Display the information text.
- ;
- 'ABOUT': begin
- if (Xregistered('XDisplayFile') ne 0) then begin
- WIDGET_CONTROL,Event.Top, SET_UVALUE=UVAL, /NO_COPY
- RETURN
- endif
-
- ; Display the information.
- ;
- XDisplayFile, filepath("wavelet.txt", $
- SUBDIR=['examples','demo','demotext']), $
- DONE_BUTTON='Done', $
- TITLE="Wavelet tool help", $
- GROUP=Event.top, WIDTH=55, HEIGHT=14
- end ; of ABOUT
-
-
-
- ; Handle the compression slider event. Redo all the plots.
- ;
- 'S_COMPRESSED': begin
-
- ; Need to clear the comp image draw
- ; we are guarranteed no drag events
- ;
- WIDGET_CONTROL, UVAL.B_MAIN, SENSITIVE=0
- Move_Line, UVAL, Event.value
- New_Percentage, UVAL, Event.value
- xValue = STRING(Event.value, FORMAT='(f6.2)')
- xValue = STRTRIM(xValue,2)
- xValue = xValue + ' %'
- WIDGET_CONTROL, UVAL.SliderValue, SET_VALUE=xValue
- Do_Compression, UVAL
- WIDGET_CONTROL, UVAL.B_MAIN, SENSITIVE=1
- END
-
- ; Handle the compression plot drawing event.
- ;
- 'D_PLOT': begin
-
- CASE Event.Type of
-
- 0: begin
-
- ; Button press
- ; check which button (only left buttton is active)
- ;
- if (Event.Press EQ 1) then begin
-
- ; Start the drag process
- ;
- UVAL.DRAGGING = 1B
-
- ; Draw the first line
- ;
- WSET, UVAL.ID_PLOT
- tmp = Convert_coord(Event.X,0,/device,/to_data)
- tmp(0)= IN_RANGE (tmp(0), 0, 100)
- Move_Line, UVAL, tmp(0)
- UVAL.PERCENTAGE = tmp(0)
- endif
- END ; of 0
-
- 1: begin
-
- ; Button release
- ; check which button (only act on left)
- ;
- if (Event.Release EQ 1) then begin
-
- ; Stop the dragging
- ;
- UVAL.DRAGGING = 0B
-
- ; Evaluate percentage and update slider, etc.
- ; need to clear the comp image draw
- ;
- WSET, UVAL.ID_PLOT
- tmp = Convert_coord(Event.X,0,/device,/to_data)
- tmp(0)= IN_RANGE (tmp(0), 0, 100)
- Move_Line, UVAL, tmp(0)
- New_Percentage, UVAL, tmp(0)
- Do_Compression, UVAL
- endif
- END ; of 1
-
- 2: begin
-
- ; Motion event.
- ; Check if dragging.
- ;
- if (UVAL.DRAGGING EQ 1B) then begin
-
- ; Draw new line (xor'd)
- ;
- WSET, UVAL.ID_PLOT
- tmp = Convert_coord(Event.X,0,/device,/to_data)
- tmp(0)= IN_RANGE (tmp(0), 0, 100)
- Move_Line, UVAL, tmp(0)
- UVAL.PERCENTAGE=tmp(0)
- endif
- END ; of 2
-
- ELSE:
-
- endcase
- END
-
- ELSE: ; do nothing
-
- endcase
-
- WIDGET_CONTROL, Event.Top, SET_UVALUE=UVAL, /NO_COPY
-
- end
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Cleanup procedure.
- ;
- pro Wavelet_Cleanup, tlb
-
- ; Get the color table saved in the window's user value.
- ;
- WIDGET_CONTROL, tlb, GET_UVALUE=UVAL, /NO_COPY
-
- ; Restore the previous color table.
- ;
- TVLCT, UVAL.colorTable
-
- if widget_info(UVAL.groupBase, /valid) then $
- WIDGET_CONTROL, UVAL.groupBase, /map
-
- end ; Of Wavelet_Cleanup
-
- ;---------------------------------------------------------------------
- ;
- ; PURPOSE : Transform an image using the orthogonal
- ; wavelet method (Daubechies coefficients).
- ;
- pro D_Wavelet, $
- GROUP=group, $ ; IN: (opt) group identifier
- APPTLB = appTLB ; OUT: (opt) TLB of this application
-
- ; Check the validity of the group identifier.
- ;
- ngroup = N_ELEMENTS(group)
- if (ngroup NE 0) then begin
- check = widget_INFO(group, /valid)
- if (check NE 1) then begin
- print,'Error, the group identifier is not valid'
- print, 'Return to the main application'
- RETURN
- endif
- groupBase = group
- endif else groupBase = 0L
-
-
- CHARSIZE = 6.0 / !D.X_CH_SIZE
-
- ; Get the screeen size.
- ;
- device, GET_SCREEN_SIZE=scr
-
- myScroll = 0 ; For adding scroll bars if necessary
- if (scr(0) LT 1000) then begin
- void = $
- WIDGET_MESSAGE('This application is optimized for 1024 x 768 resolution')
- myScroll = 1 ; Add the scroll bar when creating the TLB
- endif
-
-
- ; Get the screen size and set an offset..
- ;
- Device, GET_SCREEN_SIZE = scrsize
-
- ; Create the starting up message.
- ;
- if (ngroup EQ 0) then begin
- drawbase = startmes()
- endif else begin
- drawbase = startmes(GROUP=group)
- endelse
-
- xdimImage = 256
- ydimImage = 256
- xdimBasis = 256
- ydimBasis = 256
- xdimPlot = 256
- ydimPlot = 256
-
- ; Save the current color table.
- ;
- TVLCT, savedR, savedG, savedB,/GET
- colorTable=[[savedR], [savedG], [savedB]]
-
- ; Load an new color table.
- ;
- LOADCT, 0
-
- junk = { CW_PDMENU_S, flags:0, name:'' }
-
- ; Get the tips.
- ;
- sText = getTips(filepath('wavelet.tip', $
- SUBDIR=['examples','demo', 'demotext']) )
-
- ; Create the widget hierarchy starting with the
- ; top level base.
- ;
- if (myScroll EQ 1) then begin
- if (N_ELEMENTS(group) EQ 0) then begin
- B_MAIN = WIDGET_BASE( $
- TLB_FRAME_ATTR=1, $
- SCROLL=myScroll, $
- X_SCROLL_SIZE=scrsize[0]-75, Y_SCROLL_SIZE=scrsize[1]-75, $
- /TLB_KILL_REQUEST_EVENTS, $
- COLUMN=1, MAP=0, MBAR=barBase, TITLE='WaveletTool')
- endif else begin
- B_MAIN = WIDGET_BASE(GROUP_LEADER=group, $
- TLB_FRAME_ATTR=1, $
- SCROLL=myScroll, $
- X_SCROLL_SIZE=scrsize[0]-75, Y_SCROLL_SIZE=scrsize[1]-75, $
- /TLB_KILL_REQUEST_EVENTS, $
- COLUMN=1, MAP=0, MBAR=barBase, TITLE='WaveletTool')
- endelse
- endif else begin
- if (N_ELEMENTS(group) EQ 0) then begin
- B_MAIN = WIDGET_BASE( $
- TLB_FRAME_ATTR=1, $
- /TLB_KILL_REQUEST_EVENTS, $
- COLUMN=1, MAP=0, MBAR=barBase, TITLE='WaveletTool')
- endif else begin
- B_MAIN = WIDGET_BASE(GROUP_LEADER=group, $
- TLB_FRAME_ATTR=1, $
- /TLB_KILL_REQUEST_EVENTS, $
- COLUMN=1, MAP=0, MBAR=barBase, TITLE='WaveletTool')
- endelse
- endelse
-
- ; Create the file menu.
- ;
- wFileButton = WIDGET_BUTTON(barbase, VALUE='File', /MENU)
-
- wOpenButton = WIDGET_BUTTON(wFileButton, $
- VALUE='Open', UVALUE='OPEN')
-
- wQuitButton = WIDGET_BUTTON(wFileButton, $
- VALUE='Quit', UVALUE='QUIT')
-
- ; Create the option menu.
- ;
- wOptionButton = WIDGET_BUTTON(barbase, VALUE='Options', /MENU)
-
- wFourButton = WIDGET_BUTTON(wOptionButton, $
- VALUE='4 Coefficients', UVALUE='FOUR')
-
- wTwelveButton = WIDGET_BUTTON(wOptionButton, $
- VALUE='12 Coefficients', UVALUE='TWELVE')
-
- wTwentyButton = WIDGET_BUTTON(wOptionButton, $
- VALUE='20 Coefficients', UVALUE='TWENTY')
-
- wDifferenceButton = WIDGET_BUTTON(wOptionButton, $
- VALUE='Show Difference Image', UVALUE='DIFFERENCE')
-
- ; Create the tool menu.
- ;
- wViewButton = WIDGET_BUTTON(barbase, VALUE='View', /MENU)
-
- wXLoadctButton = WIDGET_BUTTON(wViewButton, $
- VALUE='Color Palette', UVALUE='XLOADCT')
-
- ; Create the Help/About button.
- ;
- wHelpButton = WIDGET_BUTTON(barbase, /HELP, Value = 'About',/Menu)
-
- wAboutButton = WIDGET_BUTTON(wHelpButton, $
- VALUE='About Wavelets', UVALUE='ABOUT')
-
- B_ALLDISP = WIDGET_BASE(B_MAIN, ROW=1, SPACE=5, XPAD=5, YPAD=5, $
- FRAME=1, MAP=1, TITLE='ALL Display', UVALUE='B_ALLDISP')
-
- ; B_DISPLAY is the base that contains the original
- ; and compressed images.
- ;
- B_DISPLAY = WIDGET_BASE(B_ALLDISP, /COLUMN, SPACE=5, $
- XPAD=5, YPAD=5, FRAME=1, MAP=1, TITLE='Display', $
- UVALUE='B_DISPLAY', /BASE_ALIGN_CENTER)
-
- B_ORIGINAL = WIDGET_BASE(B_DISPLAY, COLUMN=1, MAP=1, $
- TITLE='original_base', UVALUE='B_ORIGINAL')
-
- L_ORIGINAL = WIDGET_LABEL( B_ORIGINAL, $
- UVALUE='L_ORIGINAL', VALUE='Original:')
-
- D_ORIGINAL = WIDGET_DRAW( B_ORIGINAL, $
- RETAIN=2, UVALUE='D_ORIGINAL', $
- XSIZE=256, YSIZE=256, /FRAME)
-
- B_COMPRESSED = WIDGET_BASE(B_DISPLAY, COLUMN=1, $
- MAP=1, TITLE='compressed_base', $
- UVALUE='B_COMPRESSED')
-
- L_COMPRESSED = WIDGET_LABEL( B_COMPRESSED, $
- UVALUE='L_COMPRESSED', VALUE='Compressed:')
-
- D_COMPRESSED = WIDGET_DRAW( B_COMPRESSED, $
- RETAIN=2, UVALUE='D_COMPRESSED', $
- XSIZE=256, YSIZE=256, /FRAME)
-
- ; B_WAVEADJ is the base that contains our interface
- ; to adjust the compression amount of our wavelet basis.
- ;
- B_WAVES = WIDGET_BASE(B_ALLDISP, COLUMN=1, SPACE=5, $
- XPAD=5, YPAD=5, FRAME=1, MAP=1, $
- TITLE='Wavelets', UVALUE='B_WAVES')
-
- L_WAVES = WIDGET_LABEL( B_WAVES, $
- UVALUE='L_WAVES', VALUE='Wavelet Basis:')
-
- B_WAVEADJ = WIDGET_BASE(B_WAVES, ROW=1, SPACE=10, $
- XPAD=10, YPAD=10, FRAME=0, MAP=1, $
- TITLE='Wavelet Adjust', UVALUE='B_WAVEADJ')
-
- ; Base to hold tv's of wavelet basis.
- ;
- B_SHOWIMAGE1 = WIDGET_BASE(B_WAVEADJ, $
- /COLUMN, MAP=1, TITLE='show wavelet images', $
- UVALUE='B_SHOWIMAGE1')
-
- L_WAVE1 = WIDGET_LABEL( B_SHOWIMAGE1, $
- UVALUE='L_WAVE1', VALUE='Original:')
-
- D_WAVE1 = WIDGET_DRAW( B_SHOWIMAGE1, $
- RETAIN=2, UVALUE='D_WAVE1', $
- XSIZE=200, YSIZE=200, /FRAME)
-
- B_SHOWIMAGE2 = WIDGET_BASE(B_WAVEADJ, $
- /COLUMN, MAP=1, TITLE='show wavelet images', $
- UVALUE='B_SHOWIMAGE2')
-
- L_WAVE2 = WIDGET_LABEL( B_SHOWIMAGE2, $
- UVALUE='L_WAVE2', VALUE='Compressed:')
-
- D_WAVE2 = WIDGET_DRAW( B_SHOWIMAGE2, $
- RETAIN=2, UVALUE='D_WAVE2', $
- XSIZE=200, YSIZE=200, /FRAME)
-
- ; Base to hold plot and slider for adjusting compression.
- ;
- B_ADJCOMP = WIDGET_BASE(B_WAVES, $
- COLUMN=1, MAP=1, FRAME=0, SPACE=10, $
- XPAD=10, YPAD=10, TITLE='adjust compression', $
- UVALUE='B_ADJCOMP')
-
- L_ADJCOMP = WIDGET_LABEL( B_ADJCOMP, $
- UVALUE='L_ADJCOMP', VALUE='Adjust Compression:')
-
- D_PLOT = WIDGET_DRAW( B_ADJCOMP, RETAIN=2, $
- UVALUE='D_PLOT', $
- XSIZE=420, YSIZE=200, /FRAME, $
- /MOTION_EVENTS, /BUTTON_EVENTS)
-
- SliderValue = WIDGET_LABEL(B_ADJCOMP, $
- VALUE=' 75.00 %', /ALIGN_CENTER)
-
- S_COMPRESSED = WIDGET_SLIDER( B_ADJCOMP, $
- MAXIMUM=100, XSIZE=420, $
- TITLE='Percentage Compression', $
- UVALUE='S_COMPRESSED', $
- VALUE=75, /SUPPRESS_VALUE)
-
- ; Create the status line label.
- ;
- wStatusBase = WIDGET_BASE(B_MAIN, MAP=0, /ROW)
-
- nWidgets = 2
- wText = LONARR(nWidgets)
- widTips, wStatusBase, sText.text, XSIZE=36, $
- YSIZE=3, NWIDGETS=nWidgets, wText
-
- ; We have a second top-level base to show differences.
- ;
- B_DIFF = WIDGET_BASE(GROUP_LEADER=B_MAIN, COLUMN=1, $
- MAP=0, TITLE='WaveletTool Image Differences')
-
- D_DIFF = WIDGET_DRAW( B_DIFF, RETAIN=2, $
- XSIZE=256, YSIZE=256, /FRAME)
-
- WIDGET_CONTROL, B_MAIN, /REALIZE
- WIDGET_CONTROL, B_DIFF, MAP=0, /REALIZE
-
- ; Returns the top level base to the APPTLB keyword.
- ;
- appTLB = B_MAIN
-
- ; Size the tips widgets.
- ;
- sizeTips, B_MAIN, wText, wStatusBase
-
-
- UVAL = {ID_ORIG:0L, $ ; Windows IDs, original
- ID_COMP:0L, $ ; compressed
- ID_WAVE1:0L, $ ; wavelet 1
- ID_WAVE2:0L, $ ; wavelet 2
- ID_PLOT:0L, $ ; pecentage plot
- ID_DIFF:0L, $ ; difference image
- B_MAIN: B_MAIN, $ ; Top level base
- WID_STATUS:0L, $ ; Status label ID
- WID_SLIDER:0L, $ ; Percentage slider ID
- WID_DIFFBASE:0L, $ ; Difference image base ID
- WID_MAIN:0L, $ ; Main base ID
- WID_COEFFS:0L, $ ; Number of coefficients button IDs
- ENABLE_WIDS:LONARR(8), $ ; Enabled widgets IDs (see list below)
- THRESHOLD: 0.0, $ ; Threshold value
- COEFFS:0, $ ; Number of wavelets coefficients
- FILE_LOADED:0B, $ ; File loaded flag
- PERCENTAGE:0.0, $ ; Compression precentage value
- DRAGGING:0B, $ ; Dragging mode:0=not, 1=yes
- WFourButton: wFourButton, $ ; Widget button IDs
- WTwelveButton: wTwelveButton, $
- WTwentyButton: wTwentyButton, $
- DifferenceImage: $
- BYTARR(xdimImage, yDimImage), $ ; Difference image
- SliderValue: SliderValue, $ ; Percentage slider value
- CompressImageFlag : 0, $ ; 0= not drawn, 1=drawn
- ColorTable: colorTable, $ ; Color table to restore
- CHARSIZE: CHARSIZE, $
- WText: wText, $ ; Widget text IDs for tips
- SText: sText, $ ; Text structure for tips
- ; Set this to 1 to start to force erase of ID_COMP
- COMPRESSED:1B, $ ; Compress flag
- THRESHARRAY:FLTARR(1001), $ ; Threshold array
- ORIG_IMG:BYTARR(256,256), $ ; Original image
- WVLT_IMG:FLTARR(256,256), $ ; Wavelet image
- COMP_IMG:BYTARR(256,256), $ ; Compressed image
- groupBase: groupBase $ ; Base of Group Leader
- }
-
-
- ; The ENABLE_WIDS array is an array of widget ids
- ; to desensitize when there
- ; is no filename selected.
-
- ; Fill the UVALUE structure of our main base with our values.
- ;
- WIDGET_CONTROL, D_ORIGINAL, GET_VALUE=originalValue
- UVAL.ID_ORIG = originalValue
- WIDGET_CONTROL, D_COMPRESSED, GET_VALUE=compressedValue
- UVAL.ID_COMP = compressedValue
- WIDGET_CONTROL, D_WAVE1, GET_VALUE=wave1Value
- UVAL.ID_WAVE1 = wave1Value
- WIDGET_CONTROL, D_WAVE2, GET_VALUE=wave2Value
- UVAL.ID_WAVE2 = wave2Value
- WIDGET_CONTROL, D_PLOT, GET_VALUE=differenceValue
- UVAL.ID_PLOT = differenceValue
- WIDGET_CONTROL, D_DIFF, GET_VALUE=differenceValue
- UVAL.ID_DIFF = differenceValue
- UVAL.WID_SLIDER = S_COMPRESSED
- UVAL.WID_DIFFBASE = B_DIFF
- UVAL.WID_MAIN = B_MAIN
- UVAL.ENABLE_WIDS = $
- [L_COMPRESSED, L_WAVE1, L_WAVE2, L_ADJCOMP, L_ORIGINAL, $
- L_WAVES, S_COMPRESSED, D_PLOT]
-
- ; Set up initial parameters.
- ; Clean up the windows.
- ;
- New_Coeff, UVAL, 4
- Erase_Original, UVAL
- Erase_Secondary, UVAL
- Sensitize, UVAL, 0
- textChange = ['sele1', 'sele2']
- putTips, UVAL.sText, UVAL.wText[1], $
- textChange, [1,2]
- Change_Filename, UVAL, '<NONE>'
-
-
- ; Load an initial file .
- ;
- file = 'ctscan.dat'
- GetData2, NewImage, FILENAME=file, /TWO_DIM
- Change_Filename, UVAL, file
-
- ; Adjust size of image to 256,256 if necessary.
- ;
- UVAL.ORIG_IMG = Adjust_Size (NewImage)
- UVAL.FILE_LOADED = 1B
- Sensitize, UVAL, 1
- Erase_Original, UVAL
- Erase_Secondary, UVAL
- Got_New_Image, UVAL
- textChange = ['selecto','adjus', 'perce']
- putTips, UVAL.sText, UVAL.wText[1], $
- textChange, [0,1,2]
-
- WIDGET_CONTROL, B_MAIN, SET_UVALUE=UVAL
- WIDGET_CONTROL, wFourButton, SENSITIVE=0
-
- ; Destroy the starting up window.
- ;
- WIDGET_CONTROL, drawbase, /DESTROY
-
- ; Map the top level base.
- ;
- WIDGET_CONTROL, B_MAIN, MAP=1
-
- ; Set up the default percentage value to 75 %.
- ;
- pseudoEvent = { $
- ID: S_COMPRESSED, $
- TOP: B_MAIN, $
- HANDLER: B_MAIN, $
- VALUE:75L, $
- DRAG:0 $
- }
- WaveletTool_Event, pseudoEvent
-
- ; Map the top level base.
- ;
- WIDGET_CONTROL, B_MAIN, MAP=1
-
- XMANAGER, 'D_Wavelet', B_MAIN, $
- EVENT_HANDLER='WaveletTool_Event', CLEANUP='Wavelet_Cleanup', $
- /NO_BLOCK
-
- end ; of d_wavelet
-